From 12b1cdb52a9d2723c319083b45a4e9a21896b3b4 Mon Sep 17 00:00:00 2001
From: Sebastien Castiel <sebastien@castiel.me>
Date: Wed, 6 Dec 2023 17:02:37 -0500
Subject: Balances

---
 src/app/groups/[groupId]/balances-list.tsx | 63 ++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 src/app/groups/[groupId]/balances-list.tsx

(limited to 'src/app/groups/[groupId]/balances-list.tsx')

diff --git a/src/app/groups/[groupId]/balances-list.tsx b/src/app/groups/[groupId]/balances-list.tsx
new file mode 100644
index 0000000..c0cffa9
--- /dev/null
+++ b/src/app/groups/[groupId]/balances-list.tsx
@@ -0,0 +1,63 @@
+import { Balances } from '@/lib/balances'
+import { cn } from '@/lib/utils'
+import { Participant } from '@prisma/client'
+
+type Props = {
+  balances: Balances
+  participants: Participant[]
+  currency: string
+}
+
+export function BalancesList({ balances, participants, currency }: Props) {
+  const maxBalance = Math.max(
+    ...Object.values(balances).map((b) => Math.abs(b.total)),
+  )
+
+  return (
+    <div className="text-sm">
+      {participants.map((participant) => (
+        <div
+          key={participant.id}
+          className={cn(
+            'flex',
+            balances[participant.id]?.total > 0 || 'flex-row-reverse',
+          )}
+        >
+          <div
+            className={cn(
+              'w-1/2 p-2',
+              balances[participant.id]?.total > 0 && 'text-right',
+            )}
+          >
+            {participant.name}
+          </div>
+          <div
+            className={cn(
+              'w-1/2 relative',
+              balances[participant.id]?.total > 0 || 'text-right',
+            )}
+          >
+            <div className="absolute inset-0 p-2 z-20">
+              {currency} {(balances[participant.id]?.total ?? 0).toFixed(2)}
+            </div>
+            <div
+              className={cn(
+                'absolute top-1 h-7 z-10',
+                balances[participant.id]?.total > 0
+                  ? 'bg-green-200 left-0 rounded-r-lg border border-green-300'
+                  : 'bg-red-200 right-0 rounded-l-lg border  border-red-300',
+              )}
+              style={{
+                width:
+                  (Math.abs(balances[participant.id]?.total ?? 0) /
+                    maxBalance) *
+                    100 +
+                  '%',
+              }}
+            ></div>
+          </div>
+        </div>
+      ))}
+    </div>
+  )
+}
-- 
cgit v1.3

